﻿using lsw_VoteSys.Models.Database;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace lsw_VoteSys.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CompanyController : ControllerBase
    {
        private readonly lsw_VoteSysContext _db;

        public CompanyController(lsw_VoteSysContext db)
        {
            _db = db;
        }

        /// <summary>
        /// 获取企业详情
        /// </summary>
        /// <param name="companyId">企业的ID</param>
        /// <returns>企业详情</returns>
        [HttpGet]
        [Authorize]
        public IActionResult GetCompanyDetails(int companyId)
        {
            // 根据ID获取企业详情
            var company = _db.DetailIds.FirstOrDefault(c => c.DetailId1 == companyId);

            if (company == null)
            {
                return NotFound("企业信息未找到");
            }
            return Ok(company);
        }
    }

    public class DetailId
    {
        public int DetailId1 { get; set; }
        public string CompanyName { get; set; }
        public string Founded { get; set; }
    }
}
